const webpack = require('webpack');
const path = require('path')
const env = process.env.NODE_ENV
const isProduction = env === 'production'

function resolve(dir) {
    return path.join(__dirname, dir)
}

module.exports = {
    lintOnSave: 'error',
    publicPath: isProduction ? './static' : '/',
    filenameHashing: false,
    devServer: {
        proxy: 'http://localhost:8000',
        disableHostCheck: true,
        port: 8080
    },
    configureWebpack: {
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                'window.jQuery': 'jquery',
                Popper: ['popper.js', 'default']
            })
        ]
    },
    css: {
        loaderOptions: {
            sass: {
                data: `
          @import "~@a/style/variable.scss";
        `
            }
        }
    },
    chainWebpack: (config) => {
        config.resolve.alias
            .set('@a', resolve('src/assets'))
            .set('@c', resolve('src/components'))
            .set('@s', resolve('src/service'))
            .set('@w', resolve('src/widget'))
        config.optimization.delete('splitChunks')
    }
}
